<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="cn.java71.dao.*,cn.java71.entity.*,cn.java71.util.*" %>
<%@ page import="cn.java71.service.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Date" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="laoliu" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
    <title>显示首页的学生</title>
    <script src="js/jquery-3.4.1.min.js"></script>

</head>
<body>
<form action="student" id="searchForm">
    <input type="hidden" name="p" id="p" value="1"/>
    <input type="search" id="sname" name="sname" value="${sname}" placeholder="姓名"/>
    <input type="search" id="telephone" name="telephone" value="${telephone}" placeholder="telephone"/>
    <input type="search" id="qq" name="qq" value="${qq}" placeholder="qq"/>
    <input type="date" id="startdate" name="startdate" value="${startdate}" placeholder="入学时间的起点"/>
    <input type="date" id="enddate" name="enddate" value="${enddate}" placeholder="入学时间的终点"/>
    <input type="submit" value="查找"/>
</form>

<table border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>手机号</th>
        <th>入学日期</th>
        <th>年级</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${students.datas}" var="stu">
    <tr>
        <td>${stu.stuno}</td>
        <td>${stu.sname}</td>
       <td>${stu.telephone}</td>
        <td>
        <laoliu:formatDate value="${stu.enterdate}" pattern="yy年MM月dd日"/>
        </td>
        <td>${stu.gname}</td>
        <td>
            <a href="showStudentServlet?stuno=${stu.stuno}">查看信息</a>
            <a onclick="return confirm('真的要删除${stu.sname}？')"
               href="delStudentServlet?stuno=${stu.stuno}">删除</a>
            <a href="studentUpdate.jsp?stuno=${stu.stuno}">修改</a>
        </td>
    </tr>

    </c:forEach>
</table>
</ul>
<p align="center" id="pager">
    <a href="#" id="first">首页</a>
    <c:if test="${students.pageNo>1}">
        <a href="#" id="prev">上一页</a>
    </c:if>


    <input type="number" min="1" max="${students.getTotalPages()}" name="p" id="jump" size="4" value="${p}" style="width: 50px"/>

    <c:if test="${students.pageNo<students.totalPages}">
        <a href="#" id="next">下一页</a>
    </c:if>

    <a href="#" id="last">末页</a>
</p>
<script>
    $(function () {

        $("#jump").keypress(function (event) {
            //alert($(this).attr("max"));
            if(event.keyCode==13){
                if(parseInt($(this).val())>parseInt($(this).attr("max"))){
                    alert("超了");
                    return false;
                }
                window.location.href="student?p="+$(this).val()+"&sname="+$("#sname").val();
            }
        }).blur(function () {
            if(parseInt($(this).val())>parseInt($(this).attr("max"))){
                alert("超了");
                return false;
            }

            window.location.href="student?p="+$(this).val()+"&sname="+$("#sname").val();
        });

        //点击上一个，下一个
        var curr=${students.pageNo};
        $("#pager a#prev").click(function () {
            curr--;
            $("form#searchForm :hidden[name=p]").val(curr);
            $("form#searchForm").submit();
            return false;
        });
        $("#pager a#next").click(function () {
            curr++;
            $("form#searchForm :hidden[name=p]").val(curr);
            $("form#searchForm").submit();
            return false;
        });
        $("#pager a#last").click(function () {
            curr=${students.totalPages};
            $("form#searchForm :hidden[name=p]").val(curr);
            $("form#searchForm").submit();
            return false;
        });
    });
</script>
</body>
</html>
